package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.common.aop.annotation.LogAnnotation;
import com.company.project.entity.SysUser;
import com.company.project.entity.TSeatsEntity;
import com.company.project.mapper.TSeatsMapper;
import com.company.project.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.TGhszEntity;
import com.company.project.service.TGhszService;

import javax.annotation.Resource;


/**
 * 
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2024-01-12 19:33:30
 */
@Controller
@RequestMapping("/")
public class TGhszController {
    @Resource
    private TGhszService tGhszService;
    @Resource
    private UserService userService;
    @Resource
    private TSeatsMapper tSeatsMapper;

    /**
    * 跳转到页面
    */
    @GetMapping("/index/tGhsz")
    public String tGhsz() {
        return "tghsz/list";
        }


    @GetMapping("/index/tGhsz/add")
    public String tGhszAdd() {
        return "tghsz/add";
    }
    @GetMapping("/index/tGhsz/eidt/{id}")
    public String tGhszEidt(Model model, @PathVariable("id") String id) {
        model.addAttribute("ghszId",id);
        return "tghsz/eidt";
    }

    @ApiOperation(value = "新增")
    @PostMapping("tGhsz/add")
    @RequiresPermissions("tGhsz:add")
    @LogAnnotation(title = "公海设置", action = "新增")
    @ResponseBody
    public DataResult add(@RequestBody TGhszEntity tGhsz){
        SysUser userInfo = userService.getUserInfo();
        TSeatsEntity tSeatsEntity = tSeatsMapper.selectOne(Wrappers.<TSeatsEntity>lambdaQuery().eq(TSeatsEntity::getAccountid, userInfo.getId()));
        tGhsz.setSsgs(tSeatsEntity.getCorporatename());
        tGhsz.setKhsl(0);
        tGhsz.setStart("0");
        tGhszService.save(tGhsz);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("tGhsz/delete")
    @RequiresPermissions("tGhsz:delete")
    @LogAnnotation(title = "公海设置", action = "删除")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        return tGhszService.removeIds(ids);
    }
    @ApiOperation(value = "启用")
    @PostMapping("tGhsz/sta")
    @LogAnnotation(title = "公海设置", action = "启用")
    @ResponseBody
    public DataResult sta(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        tGhszService.sta(ids);
        return DataResult.success();
    }
    @ApiOperation(value = "禁用")
    @PostMapping("tGhsz/nosta")
    @LogAnnotation(title = "公海设置", action = "禁用")

    @ResponseBody
    public DataResult nosta(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        tGhszService.nosta(ids);
        return DataResult.success();
    }
    @ApiOperation(value = "更新")
    @PutMapping("tGhsz/update")
    @RequiresPermissions("tGhsz:update")
    @LogAnnotation(title = "公海设置", action = "更新")
    @ResponseBody
    public DataResult update(@RequestBody TGhszEntity tGhsz){
        tGhszService.updateById(tGhsz);
        return DataResult.success();
    }
    @ApiOperation(value = "初始化数据")
    @GetMapping("tGhsz/infoData")
    @LogAnnotation(title = "公海设置", action = "初始化数据")
    @ResponseBody
    public DataResult infoData(){
        return tGhszService.infoData();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("tGhsz/listByPage")
    @LogAnnotation(title = "公海设置", action = "查询分页数据")
    @RequiresPermissions("tGhsz:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody TGhszEntity tGhsz){
        Page page = new Page(tGhsz.getPage(), tGhsz.getLimit());
        SysUser userInfo = userService.getUserInfo();
        TSeatsEntity tSeatsEntity = tSeatsMapper.selectOne(Wrappers.<TSeatsEntity>lambdaQuery().eq(TSeatsEntity::getAccountid, userInfo.getId()));
        tGhsz.setSsgs(tSeatsEntity.getCorporatename());

        IPage<TGhszEntity> iPage = tGhszService.pageByEntity(page, tGhsz);
        return DataResult.success(iPage);
    }

    @ApiOperation(value = "查询详情")
    @LogAnnotation(title = "公海设置", action = "查询详情")
    @PostMapping("tGhsz/infoDataById/{id}")
    @ResponseBody
    public DataResult getDataById(@PathVariable("id") String id) {
        return tGhszService.getDataById(id);
    }
}
